Sketchup::LayersObserver
| Author | Manuela Ruiz (mruiz@lcc.uma.es) |
This class represents the observer for the layers
Method that triggers when the current active layer is changed
# File lib/layers.rb, line 12
12: def onCurrentLayerChanged(layers, layer)
13: #If layer does not exist...
14: if !Shade.project.execution.current_shape.p[layer.name]
15:
16: Shade.project.modifying = true
17:
18: # Draw vertical line
19: point1 = Constants::PTS_V[0].clone
20: point2 = Constants::PTS_V[1].clone
21: group = Sketchup.active_model.entities.add_group
22: group.entities.add_line point1,point2
23: group.layer = layer
24:
25: #Update the rules
26: Shade.project.execution.grammar.rules.each_with_index { |rule, i|
27:
28: #Choose first non-empty layer
29: found = false
30: j = 0
31: n_layers = Sketchup.active_model.layers.length
32: layer_name = "Layer0"
33:
34: #The content of the new layer is the same that is inside the first non-empty layer in the left shape of the rule
35: while (!found and (j < n_layers))
36: layer_name = Sketchup.active_model.layers[j].name
37:
38: if rule.alpha.p[layer_name]
39: found = (rule.alpha.p[layer_name].size > 0)
40: end
41:
42: j += 1
43: end
44:
45: if !(rule.left.s[layer.name])
46: rule.left.s[layer.name] = rule.left.s[layer_name].clone
47: rule.left.p[layer.name] = rule.left.p[layer_name].clone
48: rule.left.paint()
49: end
50:
51: if !(rule.right.s[layer.name])
52: rule.right.s[layer.name] = rule.right.s[layer_name].clone
53: rule.right.p[layer.name] = rule.right.p[layer_name].clone
54: rule.right.paint()
55: end
56:
57: #Paint the rule layout (arrow, crosses and horizontal line)
58: ShadeUtils.paint_rule_layout(i, layer.name)
59: }
60:
61: #Update the current shape
62: #Choose first non-empty layer
63: found = false
64: j = 0
65: n_layers = Sketchup.active_model.layers.length
66: layer_name = "Layer0"
67: #The content of the new layer is the same that is inside the first non-empty layer in the current_shape
68: while (!found and (j < n_layers))
69: layer_name = Sketchup.active_model.layers[j].name
70:
71: if Shade.project.execution.current_shape.p[layer_name]
72: found = (Shade.project.execution.current_shape.p[layer_name].size > 0)
73: end
74:
75: j += 1
76: end
77:
78: Shade.project.execution.current_shape.s[layer.name] = Shade.project.execution.current_shape.s[layer_name].clone
79: Shade.project.execution.current_shape.p[layer.name] = Shade.project.execution.current_shape.p[layer_name].clone
80: Shade.project.execution.current_shape.create_pi
81:
82: Shade.project.execution.current_shape.paint(Shade.project.execution.show_labels, layer)
83:
84: #Update the axiom
85: #Choose first non-empty layer
86: found = false
87: j = 0
88: n_layers = Sketchup.active_model.layers.length
89: layer_name = "Layer0"
90: #The content of the new layer is the same that is inside the first non-empty layer in the current_shape
91: while (!found and (j < n_layers))
92: layer_name = Sketchup.active_model.layers[j].name
93:
94: if Shade.project.execution.grammar.axiom.p[layer_name]
95: if Shade.project.execution.grammar.axiom.p[layer_name]
96: found = (Shade.project.execution.grammar.axiom.p[layer_name].size > 0)
97: end
98: end
99:
100: j += 1
101: end
102:
103: Shade.project.execution.grammar.axiom.s[layer.name] = Shade.project.execution.grammar.axiom.s[layer_name].clone
104: Shade.project.execution.grammar.axiom.p[layer.name] = Shade.project.execution.grammar.axiom.p[layer_name].clone
105:
106: Shade.project.execution.grammar.saved = false
107:
108: Shade.project.modifying = false
109: else
110: #Update the rules
111: Shade.project.execution.grammar.rules.each_with_index { |rule, i|
112: rule.left.paint()
113: rule.right.paint()
114: #Paint the rule layout (arrow, crosses and horizontal line)
115: ShadeUtils.paint_rule_layout(i, layer.name)
116: }
117:
118: #Update the current shape
119: Shade.project.execution.current_shape.paint(Shade.project.execution.show_labels)
120: end
121:
122:
123: end
Method that triggers then a layer is removed
# File lib/layers.rb, line 126
126: def onLayerRemoved(layers, layer)
127: Shade.project.execution.grammar.rules.each { |rule|
128: rule.left.s.delete layer.name
129: rule.left.p.delete layer.name
130: rule.left.shape_transformation.delete layer.name
131:
132: rule.right.s.delete layer.name
133: rule.right.p.delete layer.name
134: rule.left.shape_transformation.delete layer.name
135: }
136: Shade.project.execution.current_shape.s.delete layer.name
137: Shade.project.execution.current_shape.p.delete layer.name
138:
139: Shade.project.execution.grammar.saved = false
140: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.